package cn.tanghom.support.quartz;

import cn.tanghom.support.utils.LoggerUtils;
import cn.tanghom.support.utils.PropertiesUtils;
import cn.tanghom.support.utils.YunPianSms;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

/**
 */
public class MsgQuartz {

    public void job() {
        String url = PropertiesUtils.findPropertiesKey("msg_server_url");
        System.out.println(url);
        int s = 0;
        String ret = "程序运行异常";
        CloseableHttpClient client = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        try {
            HttpGet method = new HttpGet(url);
            response = client.execute(method);
            LoggerUtils.info(response);
            int stat = response.getStatusLine().getStatusCode();
            if (stat != HttpStatus.SC_OK) {
                ret = stat+"";
            } else {
                s = 1;
                ret = "程序运行正常";
            }
        } catch (Exception e) {
            ret = e.getMessage();
            e.printStackTrace();
        } finally {
            try {
                response.close();
            } catch (Exception e) {
                ret = e.getMessage();
                e.printStackTrace();
            }
        }
        if(s==0){
            System.out.println(YunPianSms.getUserInfo());
            System.out.println(ret);
            System.out.println(YunPianSms.sendSms(ret,"18613236735"));
        }
        LoggerUtils.info(ret);
    }

    public static void main(String[] args) {
        new MsgQuartz().job();
    }

}
